<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>用户管理</title>
    <jsp:include page="../../inc.jsp"></jsp:include>
    <script type="text/javascript">
        var dataGrid;
        var initOptions
        $(function () {
            var newOptions = {
                textField: 'deptName',
                columns: [[{
                    title: '编号',
                    width: 150,
                    checkbox: true
                }, {
                    field: 'id',
                    title: '部门代码',
                    width: 100
                }, {
                    field: 'deptName',
                    title: '部门名称',
                    width: 100
                }, {
                    field: 'deptMen',
                    title: '部门负责人',
                    width: 150
                }]]
            }
            initComboDataGrid("/deptController/deptList.html", $("#dept"), newOptions);
            var newOptions2 = {
                textField: 'roleName',
                columns: [[{
                    title: '编号',
                    field: 'id',
                    width: 150,
                    checkbox: true
                }, {
                    field: 'roleName',
                    title: '角色名称',
                    width: 150
                }, {
                    field: 'roleInfo',
                    title: '角色说明',
                    width: 150
                }]]
            }
            initComboDataGrid("/roleController/roleManage.html", $("#roles"), newOptions2);
            initOptions = {
                frozenColumns: [[{
                    field: 'id',
                    title: '编号',
                    width: 150,
                    checkbox: true
                }, {
                    field: 'userNo',
                    title: '工号',
                    width: 80
                }, {
                    field: 'userName',
                    title: '账号',
                    width: 80
                }, {
                    field: 'trueName',
                    title: '员工姓名',
                    width: 80
                }]],
                columns: [[

                    {
                        field: 'deptName',
                        title: '所属部门',
                        width: 150
                    }, {
                        field: 'position',
                        title: '职务',
                        width: 150
                    },
                    {
                        field: 'sex',
                        title: '性别',
                        width: 150
                    }, {
                        field: 'status',
                        title: '状态',
                        width: 150
                    }, {
                        field: 'email',
                        title: '邮件',
                        width: 150
                    }, {
                        field: 'mobile',
                        title: '手机',
                        width: 150
                    }, {
                        field: 'address',
                        title: '联系地址',
                        width: 150
                    }
                ]],
                toolbar: '#toolbar'
            }
            dataGrid = initAjaxDataGrid("/sysUserController/selectUser.html", $('#userDataGrid'), initOptions)
        });

        function editFunction() {
            var select = $('#userDataGrid').datagrid('getSelections');
            if (select&&select.length>0) {
                editFun('编辑用户', '/sysUserController/userUpdate.html?id=', $('#userDataGrid'), {
                    "width": 800,
                    "height": 460
                });
            } else {
                parent.$.messager.alert('提示', '请选择一条数据.', 'info');
            }

        }

        function addFunction() {
            addFun("添加用户", "/sysUserController/userAdd.html", $('#userDataGrid'), {"width": 800, "height": 460});
        }


        function deleteFunction() {
            var select = $('#userDataGrid').datagrid('getSelections');
            if (select&&select.length>0) {
                var rows = $('#userDataGrid').datagrid('getSelections');
                var ids = [];
                ids.push(rows[0].id);
                if ($.inArray("1", ids) != -1) {
                    $.messager.alert("删除提示", '不能删除admin用户!', 'info');
                } else {
                    deleteFun('您是否要删除当前用户信息？', '/sysUserController/deleteUser.html', $('#userDataGrid'));
                }
            } else {
                parent.$.messager.alert('提示', '请选择一条数据.', 'info');
            }
        }

        function responseFunction() {
            var select = $('#userDataGrid').datagrid('getSelections');
            if (select&&select.length>0) {
                grantFun("分配部门", "/sysUserController/distributeDept.html?id=", $('#userDataGrid'));
            } else {
                parent.$.messager.alert('提示', '请选择一条数据.', 'info');
            }
        }

        function forbiddenFunction() {
            var select = $('#userDataGrid').datagrid('getSelections');
            if (select&&select.length>0) {
                deleteFun('您是否要停用当前用户？', '/sysUserController/disableSysUser.html', $('#userDataGrid'));
            } else {
                parent.$.messager.alert('提示', '请选择一条数据.', 'info');
            }

        }

        function grantFunction() {
            var select = $('#userDataGrid').datagrid('getSelections');
            if (select&&select.length>0) {
                grantFun("分配角色", "/sysUserController/userGrant.html?id=", $('#userDataGrid'));
            } else {
                parent.$.messager.alert('提示', '请选择一条数据.', 'info');
            }
        }

        function searchFun() {
            initOptions.postData = $.serializeObject($('#searchForm'));
            initAjaxDataGrid("/sysUserController/selectUser.html", $('#userDataGrid'), initOptions);
            return false;
        }
    </script>
</head>
<body>
<div class="easyui-layout" data-options="fit : true,border : false">
    <div data-options="region:'north',title:'查询条件',border:false" style="height: 120px; overflow: hidden;">
        <form id="searchForm">
            <div class="mTop20 mLeft60">
                <div class="mTop10 line-handsome">
                    <div class="fLeft label-handsome ">
                        <label>工号:</label>
                        <input id="sys-employee-gh" name="userNo" class="easyui-input"/>

                    </div>
                    <div class="fLeft label-handsome ">
                        <label>账号:</label>
                        <input id="sys-employee-zh" name="userName" class="easyui-input"/>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>姓名:</label>
                        <input id="sys-employee-xm" name="trueName" class="easyui-input"/>
                    </div>
                </div>

                <div class="mTop10 line-handsome">
                    <div class="fLeft label-handsome ">
                        <label>部门:</label>
                        <select id="dept" class="easyui-combobox" name="deptNo" style="width:150px">
                        </select>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>角色:</label>
                        <select id="roles" class="easyui-combobox" name="roleId" style="width:150px">
                        </select>
                    </div>
                    <div class="fLeft">
                        <a href="javascript:void(0);" class="easyui-linkbutton"
                           data-options="iconCls:'icon-search'" onclick="searchFun()">搜索</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton"
                           data-options="iconCls:'brick_delete'" onclick="cleanFun();">清空搜索条件</a>
                    </div>
                </div>
            </div>
            <%--</table>--%>
        </form>
    </div>
    <div data-options="region:'center',border:false">
        <table id="userDataGrid"></table>
    </div>
</div>
<div id="toolbar" style="display: none;">
    <a onclick="addFunction();" href="javascript:void(0);" class="easyui-linkbutton"
       data-options="plain:true,iconCls:'style_add'">添加</a>
    <a onclick="editFunction();" href="javascript:void(0);" class="easyui-linkbutton"
       data-options="plain:true,iconCls:'style_edit'">编辑</a>
    <a onclick="grantFunction();" href="javascript:void(0);" class="easyui-linkbutton"
       data-options="plain:true,iconCls:'book_key'">分配角色</a>
    <a onclick="responseFunction();" href="javascript:void(0);" class="easyui-linkbutton"
       data-options="plain:true,iconCls:'style_delete'">分配负责部门</a>
    <%--<a onclick="deleteFunction();" href="javascript:void(0);" class="easyui-linkbutton"--%>
       <%--data-options="plain:true,iconCls:'style_delete'">删除</a>--%>
    <a onclick="forbiddenFunction();" href="javascript:void(0);" class="easyui-linkbutton"
       data-options="plain:true,iconCls:'style_delete'">停用</a>
</div>

<div id="menu" class="easyui-menu" style="width: 120px; display: none;">
    <div onclick="addFunction();" data-options="iconCls:'pencil_add'">增加</div>
    <div onclick="deleteFunction();" data-options="iconCls:'pencil_delete'">删除</div>
    <div onclick="editFunction();" data-options="iconCls:'pencil'">编辑</div>
</div>
</body>
</html>